<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class PP - pp: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-PP-label-What+PP+Does">What PP Does</a>
    <li><a href="#class-PP-label-Usage">Usage</a>
    <li><a href="#class-PP-label-Output+Customization">Output Customization</a>
    <li><a href="#class-PP-label-Pretty-Print+JSON">Pretty-Print JSON</a>
    <li><a href="#class-PP-label-Author">Author</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">PrettyPrint
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="PP/PPMethods.html">PP::PPMethods</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-pp">::pp</a>
    <li ><a href="#method-c-sharing_detection">::sharing_detection</a>
    <li ><a href="#method-c-sharing_detection-3D">::sharing_detection=</a>
    <li ><a href="#method-c-singleline_pp">::singleline_pp</a>
    <li ><a href="#method-c-width_for">::width_for</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-PP">
    <h1 id="class-PP" class="class">
      class PP
    </h1>

    <section class="description">
    
<p>A pretty-printer for Ruby objects.</p>

<h2 id="class-PP-label-What+PP+Does">What <a href="PP.html"><code>PP</code></a> Does<span><a href="#class-PP-label-What+PP+Does">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Standard output by p returns this:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;PP:0x81fedf0 @genspace=#&lt;Proc:0x81feda0&gt;, @group_queue=#&lt;PrettyPrint::GroupQueue:0x81fed3c @queue=[[#&lt;PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false&gt;], []]&gt;, @buffer=[], @newline=&quot;\n&quot;, @group_stack=[#&lt;PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false&gt;], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#&lt;IO:0x8114ee4&gt;&gt;</span>
</pre>

<p>Pretty-printed output returns this:</p>

<pre>#&lt;PP:0x81fedf0
 @buffer=[],
 @buffer_width=0,
 @genspace=#&lt;Proc:0x81feda0&gt;,
 @group_queue=
  #&lt;PrettyPrint::GroupQueue:0x81fed3c
   @queue=
    [[#&lt;PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0&gt;],
     []]&gt;,
 @group_stack=
  [#&lt;PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0&gt;],
 @indent=0,
 @maxwidth=79,
 @newline=&quot;\n&quot;,
 @output=#&lt;IO:0x8114ee4&gt;,
 @output_width=2&gt;</pre>

<h2 id="class-PP-label-Usage">Usage<span><a href="#class-PP-label-Usage">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre>pp(obj)             #=&gt; obj
pp obj              #=&gt; obj
pp(obj1, obj2, ...) #=&gt; [obj1, obj2, ...]
pp()                #=&gt; nil</pre>

<p>Output <code>obj(s)</code> to <code>$&gt;</code> in pretty printed format.</p>

<p>It returns <code>obj(s)</code>.</p>

<h2 id="class-PP-label-Output+Customization">Output Customization<span><a href="#class-PP-label-Output+Customization">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>To define a customized pretty printing function for your classes, redefine method <code>#pretty_print(pp)</code> in the class.</p>

<p><code>#pretty_print</code> takes the <code>pp</code> argument, which is an instance of the <a href="PP.html"><code>PP</code></a> class. The method uses text, breakable, nest, group and <a href="PP/PPMethods.html#method-i-pp"><code>pp</code></a> to print the object.</p>

<h2 id="class-PP-label-Pretty-Print+JSON">Pretty-Print JSON<span><a href="#class-PP-label-Pretty-Print+JSON">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>To pretty-print JSON refer to JSON#pretty_generate.</p>

<h2 id="class-PP-label-Author">Author<span><a href="#class-PP-label-Author">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Tanaka Akira &lt;akr@fsij.org&gt;</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-pp" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pp</span><span
                                class="method-args">(obj, out=$&gt;, width=width_for(out))</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Outputs <code>obj</code> to <code>out</code> in pretty printed format of <code>width</code> columns in width.</p>

<p>If <code>out</code> is omitted, <code>$&gt;</code> is assumed. If <code>width</code> is omitted, the width of <code>out</code> is assumed (see <a href="PP.html#method-c-width_for"><code>width_for</code></a>).</p>

<p><a href="PP.html#method-c-pp"><code>PP.pp</code></a> returns <code>out</code>.</p>

                              <div class="method-source-code" id="pp-source">
            <pre><span class="ruby-comment"># File pp.rb, line 94</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PP</span>.<span class="ruby-identifier ruby-title">pp</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">out</span>=<span class="ruby-identifier">$&gt;</span>, <span class="ruby-identifier">width</span>=<span class="ruby-identifier">width_for</span>(<span class="ruby-identifier">out</span>))
  <span class="ruby-identifier">q</span> = <span class="ruby-constant">PP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">out</span>, <span class="ruby-identifier">width</span>)
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">guard_inspect_key</span> {<span class="ruby-identifier">q</span>.<span class="ruby-identifier">pp</span> <span class="ruby-identifier">obj</span>}
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">flush</span>
  <span class="ruby-comment">#$pp = q</span>
  <span class="ruby-identifier">out</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\n&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-sharing_detection" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sharing_detection</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the sharing detection flag as a boolean value. It is false (nil) by default.</p>

                              <div class="method-source-code" id="sharing_detection-source">
            <pre><span class="ruby-comment"># File pp.rb, line 123</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sharing_detection</span>
  <span class="ruby-constant">Ractor</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:pp_sharing_detection</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-sharing_detection-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sharing_detection=</span><span
                                class="method-args">(b)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the sharing detection flag to b.</p>

                              <div class="method-source-code" id="sharing_detection-3D-source">
            <pre><span class="ruby-comment"># File pp.rb, line 127</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sharing_detection=</span>(<span class="ruby-identifier">b</span>)
  <span class="ruby-constant">Ractor</span>.<span class="ruby-identifier">current</span>[<span class="ruby-value">:pp_sharing_detection</span>] = <span class="ruby-identifier">b</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-singleline_pp" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">singleline_pp</span><span
                                class="method-args">(obj, out=$&gt;)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Outputs <code>obj</code> to <code>out</code> like <a href="PP.html#method-c-pp"><code>PP.pp</code></a> but with no indent and newline.</p>

<p><a href="PP.html#method-c-singleline_pp"><code>PP.singleline_pp</code></a> returns <code>out</code>.</p>

                              <div class="method-source-code" id="singleline_pp-source">
            <pre><span class="ruby-comment"># File pp.rb, line 106</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PP</span>.<span class="ruby-identifier ruby-title">singleline_pp</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">out</span>=<span class="ruby-identifier">$&gt;</span>)
  <span class="ruby-identifier">q</span> = <span class="ruby-constant">SingleLine</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">out</span>)
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">guard_inspect_key</span> {<span class="ruby-identifier">q</span>.<span class="ruby-identifier">pp</span> <span class="ruby-identifier">obj</span>}
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">flush</span>
  <span class="ruby-identifier">out</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-width_for" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">width_for</span><span
                                class="method-args">(out)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the usable width for <code>out</code>. As the width of <code>out</code>:</p>
<ol><li>
<p>If <code>out</code> is assigned to a tty device, its width is used.</p>
</li><li>
<p>Otherwise, or it could not get the value, the <code>COLUMN</code> environment variable is assumed to be set to the width.</p>
</li><li>
<p>If <code>COLUMN</code> is not set to a non-zero number, 80 is assumed.</p>
</li></ol>

<p>And finally, returns the above width value - 1.</p>
<ul><li>
<p>This -1 is for Windows command prompt, which moves the cursor to the next line if it reaches the last column.</p>
</li></ul>

                              <div class="method-source-code" id="width_for-source">
            <pre><span class="ruby-comment"># File pp.rb, line 77</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PP</span>.<span class="ruby-identifier ruby-title">width_for</span>(<span class="ruby-identifier">out</span>)
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;io/console&#39;</span>
    <span class="ruby-identifier">_</span>, <span class="ruby-identifier">width</span> = <span class="ruby-identifier">out</span>.<span class="ruby-identifier">winsize</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>, <span class="ruby-constant">NoMethodError</span>, <span class="ruby-constant">SystemCallError</span>
  <span class="ruby-keyword">end</span>
  (<span class="ruby-identifier">width</span> <span class="ruby-operator">||</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&#39;COLUMNS&#39;</span>]&amp;.<span class="ruby-identifier">to_i</span>&amp;.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">||</span> <span class="ruby-value">80</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

